package com.eduhzy.ttw.clazz.di.module;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.eduhzy.ttw.clazz.R;
import com.eduhzy.ttw.clazz.mvp.contract.ClazzReviewContract;
import com.eduhzy.ttw.clazz.mvp.model.ClazzReviewModel;
import com.eduhzy.ttw.clazz.mvp.model.entity.ReviewStudentData;
import com.eduhzy.ttw.commonsdk.holder.AutoBaseViewHolder;
import com.eduhzy.ttw.commonsdk.http.CommonApi;
import com.jess.arms.di.scope.ActivityScope;

import java.util.ArrayList;
import java.util.List;

import dagger.Module;
import dagger.Provides;

/**
 * @author xubo
 * @date 2018-12-4 11:15:26
 */
@Module
public class ClazzReviewModule {
    private ClazzReviewContract.View view;

    /**
     * 构建ClazzReviewModule时,将View的实现类传进来,这样就可以提供View的实现类给presenter
     *
     * @param view
     */
    public ClazzReviewModule(ClazzReviewContract.View view) {
        this.view = view;
    }

    @ActivityScope
    @Provides
    ClazzReviewContract.View provideClazzReviewView() {
        return this.view;
    }

    @ActivityScope
    @Provides
    ClazzReviewContract.Model provideClazzReviewModel(ClazzReviewModel model) {
        return model;
    }

    @ActivityScope
    @Provides
    List<ReviewStudentData> provideLists() {
        return new ArrayList<>();
    }

    @ActivityScope
    @Provides
    BaseQuickAdapter<ReviewStudentData, AutoBaseViewHolder> providerAdapter(List<ReviewStudentData> lists) {
        return new BaseQuickAdapter<ReviewStudentData, AutoBaseViewHolder>(R.layout.clazz_rv_item_review_student, lists) {
            @Override
            protected void convert(AutoBaseViewHolder helper, ReviewStudentData item) {
                helper.setText(R.id.tv_name, item.getStudentName());
                helper.setGone(R.id.btn_add, !item.isAll());
                helper.setGone(R.id.btn_del, !item.isAll());
                Glide.with(mContext)
                        .load(item.getStudentId() == 0 ? R.drawable.img_clazz : CommonApi.APP_AVATAR + item.getStudentId())
                        .apply(RequestOptions.placeholderOf(R.drawable.img_touxiang).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL))
                        .into((ImageView) helper.getView(R.id.iv_icon));
                if (!item.isAll()) {
                    helper.setText(R.id.btn_add, item.getPraiseScore() + "");
                    helper.setText(R.id.btn_del, item.getImprovingScore() + "");
                }
            }
        };

    }

    @ActivityScope
    @Provides
    RecyclerView.LayoutManager provideLayoutManager() {
        return new GridLayoutManager(view.getActivity(), 4);
    }
}